<template>
  <div class="swiper-container" ref="floor1Swiper">
    <div class="swiper-wrapper">
      <div
        class="swiper-slide"
        v-for="carousel in list"
        :key="carousel.id"
      >
        <img :src="carousel.imgUrl" />
      </div>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
  </div>
</template>

<script>
import swiper from 'swiper';
export default {
  name: "Carousel",
  props: ["list"],
  watch: {
    list: {
      //立即监听：无论数据是否变化，立马进行一次监听
      //floor中的数据是由props父传子的，数据没有发生变化，是直接使用的所以watch是监测不到的
      immediate: true,
      handler() {
        //虽然有了数据，但v-for动态渲染结构依旧无法确定，因此需要nextTick
        this.$nextTick(() => {
          var mySwiper = new swiper(this.$refs.floor1Swiper, {
            loop: true,
            //如果需要分页器
            pagination: {
              el: ".swiper-pagination",
              clickable: true,
            },
            //如果需要前后退
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },
          });
        });
      },
    },
  }
};
</script>

<style>
</style>